﻿using System;
using System.Linq;
using System.Windows.Forms;
using NBi.UI.Genbi.Presenter;

namespace NBi.UI.Genbi.Command.TestSuite
{
	class OpenTestSuiteCommand: CommandBase
	{
		private readonly TestSuitePresenter presenter;


		public OpenTestSuiteCommand(TestSuitePresenter presenter)
		{
			this.presenter = presenter;
		}

		/// <summary>
		/// Refreshes the command state.
		/// </summary>
		public override void Refresh()
		{
			this.IsEnabled = true;
		}

		/// <summary>
		/// Executes the command logics.
		/// </summary>
		public override void Invoke()
		{
			var openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "All Files (*.*)|*.*|NBi Test Suite (*.nbits)|*.nbits|Xml Files (*.xml)|*.xml";
			openFileDialog.FilterIndex = 2;
			DialogResult result = openFileDialog.ShowDialog();
			if (result == DialogResult.OK)
			{
				presenter.Load(openFileDialog.FileName);
				ShowInform(String.Format("Test-suite '{0}' loaded.", openFileDialog.FileName));
			}
				
		}
	}
}
